<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
	<head>
		<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
		<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
		<script type="text/javascript"
			src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
		<link href="${approot}/resource/jquery/validate/jquery.validate.css"
			rel="stylesheet" type="text/css" />
		<link href="${approot}/resource/jquery/validate/style.css"
			rel="stylesheet" type="text/css" />
		<script type="text/javascript">
            /* <![CDATA[ */
            jQuery(function(){
            	
               
                jQuery('#excerpt').validated(function(){
					alert("通过验证");
					do_pay_money();
				});
            });
            /* ]]> */
        </script>

		<script type="text/javascript">
        function do_pay_money()
        {   
            var str=$('#excerpt').serializeObject();
            var jsons = $.toJSON(str);
            
            pay_money(jsons);
        }


        function pay_money(jsons){
        	var str;
        	var payWise;
            if(document.getElementById('payWise_1').checked == true){
            	str = '您确认以【现金缴费】的方式处理本次操作吗?';
            	payWise = 0;
            }else if(document.getElementById('payWise_2').checked == true){
            	str = '您确认以【气票缴费】的方式处理本次操作吗?';
            	payWise = 1;
            }else if(document.getElementById('payWise_3').checked == true){
            	str = '您确认以【卡扣费】的方式处理本次操作吗?';
            	payWise = 2;
            	if(document.getElementById('card_number').value==''){
            		alert('您选择了【卡扣费】方式缴费，卡号不能为空');
            		return false;
            	}
            	if(document.getElementById('residual_money').value < document.getElementById('gas_money').value){
            		alert('您当前账户余额不足，请充值。');
            		return false;
            	}
            }else{
            	alert('系统异常');
            	return false;
            }
            var excerptId = document.getElementById('excerpt_id').value;
            var cardId = document.getElementById('card_id').value;
            var cardNumber = document.getElementById('card_number').value;
        	if(confirm(str)){
        		$.ajax({
		 		   	url:'${approot}/admin/excerpt/pay_money/'+excerptId+'/'+cardId+'/'+cardNumber+'/'+payWise,
		 		   	dataType: 'json',
		 		   	contentType: 'application/json',
		 			data:null,
		 			type:'post',
		 			beforeSend:function(){
		 			  // $('#main').disabled='true';
		 			},
		 			error:function(request){
		 				alert(S);
		 			},
		 			success:function(data){
		 			   if(data.msg=="error")
		 			   {
		 	 			   alert('缴费失败');
		 			   }
		 			   if(data.msg=="succ")
		 			   {
		 				  alert('缴费成功');
		 				  window.location.reload();
		 			   }
		 			}
		 		   });
        	}
 	    
 	}
 	
 	function show_card_number(number){
 		$.ajax( {
			url : '${approot}/admin/excerpt/get_card_list/' + number,
			dataType : 'json',
			contentType : 'application/json',
			data : null,//$.toJSON({'id':id}),
			type : 'post',
			beforeSend : function() {
				// $('#main').disabled='true';
			},
			error : function(request) {
				//alert(S);
			},
			success : function(data) {
				if (data.msg == "error") {
					alert('系统异常，获取用户卡列表失败');
				}
				if (data.msg == "succ") {
				}
				var popUp = document.getElementById("popupcontent");
				popUp.style.left = "100px";
				popUp.style.width = 600 + "px";
				popUp.innerHTML = data.sb.toString();
				popUp.style.visibility = "visible";
				document.getElementById('show_card_list').style.display = 'block';

		}
		});
 	}
 	
 	function hidePopup(){
		var popUp = document.getElementById("popupcontent");
		popUp.style.visibility = "hidden";
		popUp.innerHTML = "";
	}
	
	function hidePopupOther(){
		document.getElementById('card_id').value = '';
 		document.getElementById('card_number').value = '';
 		document.getElementById('residual_money').value = '';
 		document.getElementById('show_card_list').style.display = 'none';
 		
		var popUp = document.getElementById("popupcontent");
		popUp.style.visibility = "hidden";
		popUp.innerHTML = "";
	}
	
	function set_card_number(cardId,cardNumber,residualMoney){
		document.getElementById('card_id').value = cardId;
		document.getElementById('card_number').value = cardNumber;
		document.getElementById('residual_money').value = residualMoney;
	}
	
	function addEqui(){
		var listTable = document.getElementById("web_tab").getElementsByTagName("tbody")[0];
		
		//alert(listTable.getElementsByTagName("tbody")[0]);
		
		var addTr = document.createElement("tr") ;
		listTable.appendChild(addTr);
		
		var addTd1 = document.createElement("td");
		addTr.appendChild(addTd1);
		
		var addTd2 = document.createElement("td");
		addTr.appendChild(addTd2);
		
		var addTd3 = document.createElement("td");
		addTr.appendChild(addTd3);
		
		var addTd4 = document.createElement("td");
		addTr.appendChild(addTd4);
		
		var addTd5 = document.createElement("td");
		addTr.appendChild(addTd5);
		
		var addTd6 = document.createElement("td");
		addTr.appendChild(addTd6);
		
		var addTd7 = document.createElement("td");
		addTr.appendChild(addTd7);
		
		var addTd8 = document.createElement("td");
		addTr.appendChild(addTd8);
		
		/////
		
		var addInput1 = document.createElement("input");
		addInput1.name = "equiName" ;
		addTd1.appendChild(addInput1) ;
		
		var addInput2 = document.createElement("input");
		addInput2.name = "specification" ;
		addTd2.appendChild(addInput2) ;
		
		var addInput3 = document.createElement("input");
		addInput3.name = "amount" ;
		addTd3.appendChild(addInput3) ;
		
		var addInput4 = document.createElement("input");
		addInput4.name = "heatLoad" ;
		addTd4.appendChild(addInput4) ;
		
		var addInput5 = document.createElement("input");
		addInput5.name = "pressure" ;
		addTd5.appendChild(addInput5) ;
		
		var addInput6 = document.createElement("input");
		addInput6.name = "connType" ;
		addTd6.appendChild(addInput6) ;
		
		var addInput7 = document.createElement("input");
		addInput7.name = "portSize" ;
		addTd7.appendChild(addInput7) ;
		
		var delBar = document.createElement("a") ;
		delBar.innerHTML = "删除" ;
		delBar.href = "javascript:void(0)" ;
		delBar.onclick = function(){delRow(addTr);}
		addTd8.appendChild(delBar);
		
	}
	function delRow(obj){
		var listTable = document.getElementById("web_tab").getElementsByTagName("tbody")[0];
		listTable.removeChild(obj);
	}
        </script>

	</head>
	<body style="background: #E8F5FE; padding: 15px 18px;" class="scroll_r">
		<div id="right_w">
			<p>
				当前位置：报建管理 >> 设备登记
			</p>
		</div>

		<form method="post" name="equiRegisterForm" action="${approot}/admin/apply/register_equi" id="excerpt">
			<table border="0" cellpadding="0" cellspacing="1" width="92%"
				align="center" class="tab_l">
				<tr>
					<td>
						<b>请按要求填写：</b>
					</td>
					<td align="right">
						带<span style="color: #ff0000;">*</span>为必填
					</td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="1" width="92%"
				align="center" id="add_tab">
				<tr>
					<th width="20%">
						燃气报装单位：
						<input type="hidden" name="id" value="${er.id}" id="id">
						<input type="hidden" name="applyId" value="${er.applyId}" id="applyId">
					</th>
					<td colspan="3">
						<input name="applyDept" id="applyDept" value="${er.applyDept}"/>
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>
				<tr>
					<th width="20%">
						联系人：
					</th>
					<td width="30%">
						<input id="contacter" name="contacter" value="${er.contacter}"/>
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
					<th width="20%">
						用气地址：
					</th>
					<td width="30%">
						<input id="address" name="address" value="${er.address}"/>
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>
				<tr>
					<th width="20%">
						联系电话：
					</th>
					<td width="30%">
						<input id="tel" name="tel" value="${er.tel}"/>
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>

					<th width="20%">
						传真：
					</th>
					<td width="30%">
						<input id="fax" name="fax" value="${er.fax}"/>
						<span style="color: #ff0000; margin: 0;">*</span>
					</td>
				</tr>
				<tr>
					<th colspan="4">
						燃气设备技术参数
					</th>
				</tr>
				<tr>
					<td colspan="4" align="center">
						<table border="0" cellpadding="0" cellspacing="1" width="98%" align="center" id="web_tab">
							<tr>
								<td colspan="8" style="text-align:right;padding-right:20px"><input type="button" value="添加设备" onclick="addEqui()"/></td>
							</tr>
							<tr>
								<th align="center" >设备名称</th>
								<th align="center" >规格型号</th>
								<th align="center" >数量</th>
								<th align="center" >单台热负荷(大卡)</th>
								<th align="center" >额定工作压力</th>
								<th align="center" >连接方式</th>
								<th align="center" >接口尺寸</th>
								<th align="center" >操作</th>
							</tr>
						<c:forEach var="equi" items="${equis}">
							<tr>
								<td><input name="equiName" value="${equi.equiName}"/></td>
								<td><input name="specification" value="${equi.specification}"/></td>
								<td><input name="amount" value="${equi.amount}"/></td>
								<td><input name="heatLoad" value="${equi.heatLoad}"/></td>
								<td><input name="pressure" value="${equi.pressure}"/></td>
								<td><input name="connType" value="${equi.connType}"/></td>
								<td><input name="portSize" value="${equi.portSize}"/></td>
								<td><a href="javascript:void(0)" onclick="delRow(this.parentNode.parentNode);">删除</a></td>
							</tr>
						</c:forEach>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="4" align="center">
						<table border="0" cellpadding="0" cellspacing="1" width="98%" align="center" id="add_tab">
							<tr>
								<th width="30px" rowspan="10" align="center">燃<br>气<br>设<br>备<br>用<br>气<br>规<br>律</th>
								<th align="center"  colspan="2" width="20%">运行方式：</th>
								<td colspan="10">
									<input type="radio" name="runType" value="0" <c:if test="${er.runType==0}">checked</c:if>/>全开
									<input type="radio" name="runType" value="1" <c:if test="${er.runType==1}">checked</c:if>/>一开一备
									<input type="radio" name="runType" value="2" <c:if test="${er.runType==2}">checked</c:if>/>二开一备
									<input type="radio" name="runType" value="3" <c:if test="${er.runType==3}">checked</c:if>/>其他
								</td>
							</tr>
							<tr>
								<th align="center"  colspan="2" width="20%">小时最大用气量：</th>
								<td colspan="10">
									<input id="hourMax" name="hourMax" value="${er.hourMax}"/>
								</td>
							</tr>
							<tr>
								<th align="center"  colspan="2" width="20%">日用气时段：</th>
								<td colspan="10">
									<input id="timePart" name="timePart" value="${er.timePart}"/>
								</td>
							</tr>
							<tr>
								<th align="center"  colspan="12">通气当年月用气时段</th>
							</tr>
							<tr>
								<c:forEach begin="1" end="12" varStatus="index">
									
									<td>${index.index}月<input name="curYearPart" type="checkbox"
										<c:forEach var="curpart" items="${curYearParts}">
											<c:if test="${curpart == index.index}">checked = "true"</c:if>
										</c:forEach>
									 value="${index.index}"/>天</td>
								</c:forEach>
							</tr>
							<tr>
								<th align="center"  colspan="2">通气当年月用气规律</th>
								<td colspan="4"><input name="curUseLaw" value="${er.curUseLaw}"/></td>
								<th align="center"  colspan="2">年用气总天数</th>
								<td colspan="4"><input name="curUseDays" value="${er.curUseDays}"/></td>
							</tr>
							<tr>
								<th align="center"  colspan="12">次年月用气时段</th>
							</tr>
							<tr>
								<c:forEach begin="1" end="12" varStatus="index">
									<td>${index.index}月<input name="nextYearPart" type="checkbox"
										<c:forEach var="nextpart" items="${nextYearParts}">
											<c:if test="${nextpart == index.index}">checked = "true"</c:if>
										</c:forEach>
									 value="${index.index}"/>天</td>
								</c:forEach>
							</tr>
							<tr>
								<th align="center"  colspan="2">次年月用气规律</th>
								<td colspan="4"><input name="nextUseLaw" value="${er.nextUseLaw}"/></td>
								<th align="center"  colspan="2">年用气总天数</th>
								<td colspan="4"><input name="nextUseDays" value="${er.nextUseDays}"/></td>
							</tr>
							<tr>
								<th align="center"  colspan="2" width="20%">通气点火具体时间：</th>
								<td colspan="10">
									<input id="startDate" name="startDate" value="${er.startDate}"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<p id="tab_but">
				<input type="button" value="确 定" onclick="document.equiRegisterForm.submit();">
			</p>
		</form>
	</body>
</html>
